package leecode;

/**
 *
 *
 * @author qingyan 2021-07-05
 */
public class Question28 {
    public int strStr(String haystack, String needle) {
        if (needle.length() == 0) {
            return 0;
        }
        int m = haystack.length();
        int n = needle.length();
        for (int i = 0; i < m - n; i++) {
            if (haystack.charAt(i) == needle.charAt(0)) {
                int p = 0;
                int k = i;
                while (p < n && haystack.charAt(k) == needle.charAt(p)) {
                    k++;
                    p++;
                }
                if (p == needle.length()) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Question28 q28 = new Question28();
        int i = q28.strStr("mississippi", "issip");
        System.out.println(i);
    }
}
